8cece7
@@ -801,8 +801,15 @@
private void skipBytes(final int count) throws IOException {
     private void resolveLocalFileHeaderData(Map<ZipArchiveEntry, NameAndComment>
                                             entriesWithoutUTF8Flag)
         throws IOException {
-        for (ZipArchiveEntry ze : entries.keySet()) {
-            OffsetEntry offsetEntry = entries.get(ze);
+        // changing the name of a ZipArchiveEntry is going to change
+        // the hashcode - see COMPRESS-164
+        // Map needs to be reconstructed in order to keep central
+        // directory order
+        Map<ZipArchiveEntry, OffsetEntry> origMap =
+            new LinkedHashMap<ZipArchiveEntry, OffsetEntry>(entries);
+        entries.clear();
+        for (ZipArchiveEntry ze : origMap.keySet()) {
+            OffsetEntry offsetEntry = origMap.get(ze);
             long offset = offsetEntry.headerOffset;
             archive.seek(offset + LFH_OFFSET_FOR_FILENAME_LENGTH);
             byte[] b = new byte[SHORT];
@@ -835,6 +842,7 @@
private void resolveLocalFileHeaderData(Map<ZipArchiveEntry, NameAndComment>
                     nameMap.put(ze.getName(), ze);
                 }
             }
+            entries.put(ze, offsetEntry);
         }
     }
 
